package cn.xiongxf.service.impl;

import cn.xiongxf.domain.UserIntegralLog;
import cn.xiongxf.mapper.UserIntegralLogMapper;
import cn.xiongxf.service.IUserIntegralLogService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiongxiaofu
 * @since 2022-09-05
 */
@Service
public class UserIntegralLogServiceImpl extends ServiceImpl<UserIntegralLogMapper, UserIntegralLog> implements IUserIntegralLogService {

    /**
     * 根据用户ID获取积分
     */
    @Override
    public Integer getIntegral(Long userId) {
        // 获取用户的积分：累加
        List<UserIntegralLog> userIntegralLogs = selectList(new EntityWrapper<UserIntegralLog>().eq("user_id", userId));
        Integer integral = 0;
        for (UserIntegralLog userIntegralLog : userIntegralLogs) {
            integral += userIntegralLog.getIntegral();
        }
        return integral;
    }
}
